package com.ruoyi.operation.order.formAnalysis.controller;

import com.ruoyi.common.utils.security.ShiroUtils;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.operation.order.enter.domain.EnterForm;
import com.ruoyi.operation.order.formAnalysis.domain.FormAnalysis;
import com.ruoyi.operation.order.formAnalysis.service.IFormAnalysisService;
import com.ruoyi.operation.order.product.domain.Product;
import com.ruoyi.operation.order.product.service.IProductService;
import com.ruoyi.operation.order.total.domain.Total;
import com.ruoyi.project.system.dept.domain.Dept;
import com.ruoyi.project.system.dept.service.IDeptService;
import com.ruoyi.project.system.role.service.IRoleService;
import com.ruoyi.project.system.user.domain.User;
import com.ruoyi.project.system.user.service.IUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @Author king
 * @create 2019/4/13 13:53
 */
@RequestMapping(value = "/analysis/analysis")
@Controller
public class FormAnalysisController extends BaseController {

    // 定义一个跳转到页面的路径
    private String prefix = "order/formAnalysis/";

    @Autowired
    private IRoleService iRoleService;

    @Autowired
    private IUserService iUserService;

    @Autowired
    private IFormAnalysisService iFormAnalysisService;

    @Autowired
    private IProductService iProductService;

    @Autowired
    private IDeptService iDeptService;



    /**
     * 跳转到表格分析的页面
     * @return
     */
    @RequiresPermissions(value = "analysis:analysis:analysis")
    @GetMapping()
    String formAnalysis(){
        return prefix + "formAnalysis";
    }

    /**
     * 查询所有的列表
     * @param formAnalysis
     * @return
     */
    @RequestMapping(value = "/list")
    @RequiresPermissions(value = "analysis:analysis:analysis")
    @ResponseBody
    public TableDataInfo formAnalysis(FormAnalysis formAnalysis){

        // 获取当前登陆人的id
//        String getUserId = ShiroUtils.getLoginId();
        // 更具当前登陆人获取roleId
//        String getRoleId = iRoleService.getRoleId(getUserId);
//        if (getRoleId.equals("1") || getRoleId.equals("5")){
//            // 此时是超级管理员和鹰之队的管理员
//            formAnalysis.setType("1");
//        }else if(getRoleId.equals("3")){
//            formAnalysis.setType("2");
//            // 根据id获取对应的部门id
//            String getDeptId = iUserService.getDeptId(getUserId);
//            formAnalysis.setDeptId(getDeptId);
//        } else if(getRoleId.equals("4")){
//            // 此时是登陆人
//            formAnalysis.setType("3");
//            formAnalysis.setCreateBy(getUserId);
//        }
        startPage();
        List<FormAnalysis> formAnalysisList = iFormAnalysisService.allFormAnalysisList(formAnalysis);
        return getDataTable(formAnalysisList);
    }

    /**
     * 查询所有的产品信息
     * @return
     */
    @RequestMapping(value = "/allProduct")
    @ResponseBody
    public List<Product> allProduct(){
        return iProductService.allProduct();
    }

    /**
     * 查询所有的平台
     * @return
     */
    @RequestMapping(value = "/allDeptT")
    @ResponseBody
    public List<Dept> allDeptT(){
        return iDeptService.allDeptList();
    }

    /**
     * 查询所有的录单员
     * @return
     */
    @RequestMapping(value = "getUserByRoeId")
    @ResponseBody
    public List<User> getUserByRoeId(){
        return iUserService.getUserByRoleId();
    }


    /**
     * 导出订单信息
     * @param formAnalysis
     * @param request
     * @param response
     * @throws Exception
     */
    @RequestMapping(value = "/exportExcel")
    @RequiresPermissions(value = "analysis:analysis:export")
    public void exportExcel(FormAnalysis formAnalysis, HttpServletRequest request, HttpServletResponse response) throws Exception{
        iFormAnalysisService.exportFormAnalysis(formAnalysis,request,response);
    }
}
